<?php
session_start();
//包含头
include '../PHP/head.php';
?>
<?php
//包含bootstrap的顶端按钮
include '../PHP/menu.php';
?>


<script src="../JS/jq-ui/jquery-ui.js"></script>
<link rel="stylesheet" href="../JS/jq-ui/jquery-ui.css">
<script type="text/javascript">
//日期

	$(document).ready(function() {
    $("#deadline").datepicker({
		dateFormat: 'yy-mm-dd'
		});
	});
</script>

<br />
<br />
<p class="text-center lead">模块报价项目委托</p>
<?php
if(isset($_GET['project_id'])) {
	//查询编号信息
	require_once ('../FNS/db_fns.php');
	
	$project_id = $_GET['project_id'];
	
	//数据过滤和处理

	if (! get_magic_quotes_gpc()) {
	$project_id=addslashes ($project_id);
	}
	
	$db = db_connect();
	$query="select projects.code as project_code, projects.name as project_name, projects.sale as sale_id, projects.entrust_date, users.name as sale_name from projects inner join users on projects.sale = users.id where projects.id = '".$project_id."'";
	
	$result=$db->query ($query);
	$num_result=$result->num_rows;
	
	//拿出数据
	$row=$result->fetch_assoc ();
	$project_code = stripslashes ($row['project_code']);
	$project_name = stripslashes ($row['project_name']);
	$sale_name = stripslashes ($row['sale_name']);
	$sale_id = stripslashes ($row['sale_id']);

	
	$result->free();
	$db->close();
	//列出编号基本信息
	echo "
		<br />
		<div class='row'>
			<div class='col-md-2'><p class='text-right'>报价编号：</p></div>
			<div class='col-md-2'><p>".$project_code."</p></div>
			<div class='col-md-2'><p class='text-right'>项目名称：</p></div>
			<div class='col-md-4'><p>".$project_name."</p></div>
			<div class='col-md-1'><p class='text-right'>销售：</p></div>
			<div class='col-md-1'><p>".$sale_name."</p></div>
		</div>
		<br />
	";
	
	//列出表单
	
	echo "
	
	<form class='form-horizontal' role='form' action = '../PHP/entrust_project.php' method = 'post'>
		<input type='hidden' name = 'project_id' value = '".$project_id."'>
		<div class='form-group'>
				<label for='client' class='col-md-2 control-label'>询价公司：</label>
				<div class='col-md-4'>
					<input type = 'text'  class='form-control' placeholder='询价公司' name = 'client' />
				</div>
				<label for='enquire_no' class='col-md-2 control-label'>询价编号：</label>
				<div class='col-md-4'>
					<input type = 'text'  class='form-control' placeholder='询价编号' name = 'enquire_no' />
				</div>
		</div>
		<div class='form-group'>
				<label for='end_user' class='col-md-2 control-label'>业主名称：</label>
				<div class='col-md-4'>
					<input type = 'text'  class='form-control' placeholder='业主名称' name = 'end_user' />
				</div>
				<label for='place' class='col-md-2 control-label'>项目地点：</label>
				<div class='col-md-4'>
					<input type = 'text'  class='form-control' placeholder='项目地点' name = 'place' />
				</div>
		</div>
		<div class='form-group'>
				<label for='bid_type' class='col-md-2 control-label'>项目状态：</label>
				<div class='col-md-4'>
					<input type = 'text'  class='form-control' placeholder='预算/正式投标/工程公司中标/业主采购' name = 'bid_type' />
				</div>
				<label for='deadline' class='col-md-2 control-label'>报价截止日期：</label>
				<div class='col-md-4'>
					<input type = 'text'  class='form-control' id = 'deadline' placeholder='报价截止日期' name = 'deadline' />
				</div>
		</div>
		<div class='form-group'>
				<label for='classification' class='col-md-2 control-label'>行业分类：</label>
				<div class='col-md-4'>
					<select class='form-control' name='classification'>
						<option value='海上油气'>海上油气</option>
						<option value='陆地油气'>陆地油气</option>
						<option value='化工行业'>化工行业</option>
						<option value='农药化肥'>农药化肥</option>
						<option value='其它'>其它</option>
					</select>
				</div>
				<label for='classification_ot' class='col-md-2 control-label'>其它：</label>
				<div class='col-md-4'>
					<input type = 'text'  class='form-control' name = 'classification_ot' />
				</div>
				
		</div>
		<div class='form-group'>
				<label for='currency' class='col-md-2 control-label'>报价货币：</label>
				<div class='col-md-4'>
					<select class='form-control' name='currency'>
						<option value='USD'>USD</option>
						<option value='RMB'>RMB</option>
						<option value='EUR'>EUR</option>
					</select>
				</div>
				<label for='delivery_term' class='col-md-2 control-label'>交货条款：</label>
				<div class='col-md-4'>
					<input type = 'text' class='form-control' placeholder='FOB/EXW/CIF' name = 'delivery_term' />
				</div>
				
		</div>
		
		<br />
		<div class='form-group'>
			<div class='col-md-offset-2 col-md-3'>
				<input class='btn btn-success' type = 'submit' value='下委托'/>
			</div>
		</div>
	</form>
	
	";

}

if (isset($_POST['project_id'])) {
	
	require_once ('../FNS/db_fns.php');
	
	$project_id = trim($_POST['project_id']);
	$client = trim($_POST['client']);
	$enquire_no = trim ($_POST['enquire_no']);
	$end_user = trim($_POST['end_user']);
	$place = trim($_POST['place']);
	$bid_type = trim($_POST['bid_type']);
	$deadline = trim ($_POST['deadline']);
	$classification = trim($_POST['classification']);
	$classification_ot = trim($_POST['classification_ot']);
	$currency = trim($_POST['currency']);
	$delivery_term = trim($_POST['delivery_term']);
	
	//如果行业类别没有选择
	if ($classification == "其它") {
		$classification = $classification_ot;
	}
	//数据过滤和处理
	//加引号避免输入数据库出错	
	$project_id = addslashes ($project_id);
	$client = addslashes ($client);
	$enquire_no = addslashes ($enquire_no);
	$end_user = addslashes ($end_user);
	$place = addslashes ($place);
	$bid_type = addslashes ($bid_type);
	$deadline = addslashes ($deadline);
	$classification = addslashes ($classification);
	$classification_ot = addslashes ($classification_ot);
	$currency = addslashes ($currency);
	$delivery_term = addslashes ($delivery_term);
	$entrust_date = date ("Y-m-d");
	//连接数据库并插入数据

	$db= db_connect();

	$query="update projects set client = '".$client."', enquire_no = '".$enquire_no."', end_user = '".$end_user."', place = '".$place."', bid_type = '".$bid_type."', deadline = '".$deadline."', classification = '".$classification."', currency = '".$currency."', delivery_term = '".$delivery_term."', entrust_date = '".$entrust_date."', flag_del = '2' where id = '".$project_id."'";
	$result=$db->query ($query);
	if ($result){
		echo "<br />";
		echo "委托成功，请查询已下委托项目确认。";
	}else{
	echo "<br />";
	echo"委托失败，请重新查询未下委托项目！";
	echo $entrust_date;
	
	$db->close();
	
	
}
	
	
	
	}





?>


</div>
</body>
</html>
